home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / diff.zip / DIFF.H < prev    next >
Text File  |  1994-07-16  |  14KB  |  444 lines

  1. /* Shared definitions for GNU DIFF
  2.    Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU DIFF.
  5.  
  6. GNU DIFF is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU DIFF is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU DIFF; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  21. This port is also distributed under the terms of the GNU General
  22. Public License as published by the Free Software Foundation.
  23.  
  24. Please note that this file is not identical to the original GNU release,
  25. you should have received this code as patch to the official release.
  26.  
  27.    Friday, 15 July 1994  Troy Roll (troy@cbme.unsw.EDU.AU)
  28.         - Removed dup2 #define
  29.         - Added #include of tkexec
  30.         - Removed conditionals on many includes
  31.         - Removed "#define const <nothing>"
  32.         - Added include of alloc.h
  33.  
  34. $Header: e:/gnu/diff/RCS/diff.h 1.15.0.2 91/03/12 17:06:56 tho Exp $  */
  35.  
  36.  
  37. #include <ctype.h>
  38. #include <stdio.h>
  39. #include <sys/types.h>
  40. #include <sys/stat.h>
  41.  
  42. #include <time.h>
  43. #include <stdlib.h>
  44. #undef __STDC__
  45. #include <alloc.h>
  46. #define __STDC__ 1
  47. #include <malloc.h>
  48. #include <string.h>
  49. #include <process.h>
  50. #include <io.h>
  51. #ifdef HAVE_NDIR
  52. #ifdef NDIR_IN_SYS
  53. #include <sys/ndir.h>
  54. #else
  55. #include <ndir.h>
  56. #endif /* not NDIR_IN_SYS */
  57. #else
  58. #include <dirent.h>
  59. #endif /* not HAVE_NDIR */
  60. #include <fcntl.h>
  61. #ifndef HAVE_DIRECT
  62. #define direct dirent
  63. #endif
  64. #include <sys/tkexec.h>
  65.  
  66. #ifdef USG
  67. /* Define needed BSD functions in terms of sysV library.  */
  68.  
  69. #ifdef MSDOS
  70. #define bcopy(s,d,n)    memmove((d),(s),(n))    /* more save! */
  71. #else
  72. #define bcopy(s,d,n)    memcpy((d),(s),(n))
  73. #endif
  74. #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  75. #define bzero(s,n)    memset((s),0,(n))
  76.  
  77.  
  78. #define vfork    fork
  79. #define index    strchr
  80. #define rindex    strrchr
  81. #endif
  82.  
  83. #ifdef sparc
  84. /* vfork clobbers registers on the Sparc, so don't use it.  */
  85. #define vfork fork
  86. #endif
  87.  
  88. #include <errno.h>
  89. #ifndef MSDOS            /* have it VOLATILE in <stdlib.h> */
  90. extern int      errno;
  91. extern int      sys_nerr;
  92. extern char    *sys_errlist[];
  93. #endif /* not MSDOS */
  94.  
  95. #define    EOS        (0)
  96. #define    FALSE        (0)
  97. #define TRUE        1
  98.  
  99. #ifndef MSDOS                /* have it in <stdlib.h> */
  100. #define min(a,b) ((a) <= (b) ? (a) : (b))
  101. #define max(a,b) ((a) >= (b) ? (a) : (b))
  102. #endif
  103.  
  104. #ifndef PR_FILE_NAME
  105. #define PR_FILE_NAME "/bin/pr"
  106. #endif
  107.  
  108. /* Support old-fashioned C compilers.  */
  109. #if defined (__STDC__) || defined (__GNUC__)
  110. #include "limits.h"
  111. #else
  112. #define INT_MAX 2147483647
  113. #define CHAR_BIT 8
  114. #endif
  115.  
  116.  
  117. #ifndef O_RDONLY
  118. #define O_RDONLY 0
  119. #endif
  120.  
  121. #ifdef MSDOS
  122. #if !defined (_MSC_VER) || (_MSC_VER < 600)
  123. #define _huge huge
  124. #endif /* MSC 5.1 */
  125. #else /* not MSDOS */
  126. #define _huge
  127. #endif /* not MSDOS */
  128.  
  129. /* Variables for command line options */
  130.  
  131. #ifndef GDIFF_MAIN
  132. #define EXTERN extern
  133. #else
  134. #define EXTERN
  135. #endif
  136.  
  137. enum output_style {
  138.   /* Default output style.  */
  139.   OUTPUT_NORMAL,
  140.   /* Output the differences with lines of context before and after (-c).  */
  141.   OUTPUT_CONTEXT,
  142.   /* Output the differences in a unified context diff format (-u). */
  143.   OUTPUT_UNIFIED,
  144.   /* Output the differences as commands suitable for `ed' (-e).  */
  145.   OUTPUT_ED,
  146.   /* Output the diff as a forward ed script (-f).  */
  147.   OUTPUT_FORWARD_ED,
  148.   /* Like -f, but output a count of changed lines in each "command" (-n). */
  149.   OUTPUT_RCS,
  150.   /* Output merged #ifdef'd file (-D).  */
  151.   OUTPUT_IFDEF };
  152.  
  153. /* True for output styles that are robust,
  154.    i.e. can handle a file that ends in a non-newline.  */
  155. #define ROBUST_OUTPUT_STYLE(S) \
  156.  ((S) == OUTPUT_CONTEXT || (S) == OUTPUT_UNIFIED || (S) == OUTPUT_RCS \
  157.   || (S) == OUTPUT_NORMAL)
  158.  
  159. EXTERN enum output_style output_style;
  160.  
  161. /* Number of lines of context to show in each set of diffs.
  162.    This is zero when context is not to be shown.  */
  163. EXTERN int      context;
  164.  
  165. /* Consider all files as text files (-a).
  166.    Don't interpret codes over 0177 as implying a "binary file".  */
  167. EXTERN int    always_text_flag;
  168.  
  169. /* Ignore changes in horizontal whitespace (-b).  */
  170. EXTERN int      ignore_space_change_flag;
  171.  
  172. /* Ignore all horizontal whitespace (-w).  */
  173. EXTERN int      ignore_all_space_flag;
  174.  
  175. /* Ignore changes that affect only blank lines (-B).  */
  176. EXTERN int      ignore_blank_lines_flag;
  177.  
  178. /* Ignore changes that affect only lines matching this regexp (-I).  */
  179. EXTERN char    *ignore_regexp;
  180.  
  181. /* Result of regex-compilation of `ignore_regexp'.  */
  182. EXTERN struct re_pattern_buffer ignore_regexp_compiled;
  183.  
  184. /* 1 if lines may match even if their lengths are different.
  185.    This depends on various options.  */
  186. EXTERN int      length_varies;
  187.  
  188. /* Ignore differences in case of letters (-i).  */
  189. EXTERN int      ignore_case_flag;
  190.  
  191. /* File labels for `-c' output headers (-L).  */
  192. EXTERN char *file_label[2];
  193.  
  194. /* Regexp to identify function-header lines (-F).  */
  195. EXTERN char    *function_regexp;
  196.  
  197. /* Result of regex-compilation of `function_regexp'.  */
  198. EXTERN struct re_pattern_buffer function_regexp_compiled;
  199.  
  200. /* Say only whether files differ, not how (-q).  */
  201. EXTERN int     no_details_flag;
  202.  
  203. /* Report files compared that match (-s).
  204.    Normally nothing is output when that happens.  */
  205. EXTERN int      print_file_same_flag;
  206.  
  207. /* character that ends a line.  Currently this is always `\n'.  */
  208. EXTERN char     line_end_char;
  209.  
  210. /* Output the differences with exactly 8 columns added to each line
  211.    so that any tabs in the text line up properly (-T).  */
  212. EXTERN int    tab_align_flag;
  213.  
  214. /* Expand tabs in the output so the text lines up properly
  215.    despite the characters added to the front of each line (-t).  */
  216. EXTERN int    tab_expand_flag;
  217.  
  218. /* In directory comparison, specify file to start with (-S).
  219.    All file names less than this name are ignored.  */
  220. EXTERN char    *dir_start_file;
  221.  
  222. /* If a file is new (appears in only one dir)
  223.    include its entire contents (-N).
  224.    Then `patch' would create the file with appropriate contents.  */
  225. EXTERN int    entire_new_file_flag;
  226.  
  227. /* Pipe each file's output through pr (-l).  */
  228. EXTERN int    paginate_flag;
  229.  
  230. /* String to use for #ifdef (-D).  */
  231. EXTERN char *    ifdef_string;
  232.  
  233. /* String containing all the command options diff received,
  234.    with spaces between and at the beginning but none at the end.
  235.    If there were no options given, this string is empty.  */
  236. EXTERN char *    switch_string;
  237.  
  238. /* Nonzero means use heuristics for better speed.  */
  239. EXTERN int    heuristic;
  240.  
  241. /* Name of program the user invoked (for error messages).  */
  242. EXTERN char *    program;
  243.  
  244. /* The result of comparison is an "edit script": a chain of `struct change'.
  245.    Each `struct change' represents one place where some lines are deleted
  246.    and some are inserted.
  247.    
  248.    LINE0 and LINE1 are the first affected lines in the two files (origin 0).
  249.    DELETED is the number of lines deleted here from file 0.
  250.    INSERTED is the number of lines inserted here in file 1.
  251.  
  252.    If DELETED is 0 then LINE0 is the number of the line before
  253.    which the insertion was done; vice versa for INSERTED and LINE1.  */
  254.  
  255. struct change
  256. {
  257.   struct change *link;        /* Previous or next edit command  */
  258.   int inserted;            /* # lines of file 1 changed here.  */
  259.   int deleted;            /* # lines of file 0 changed here.  */
  260.   int line0;            /* Line number of 1st deleted line.  */
  261.   int line1;            /* Line number of 1st inserted line.  */
  262.   char ignore;            /* Flag used in context.c */
  263. };
  264.  
  265. /* Structures that describe the input files.  */
  266.  
  267. /* Data on one line of text.  */
  268.  
  269. struct line_def {
  270.     char _huge  *text;
  271.     int         length;
  272.     unsigned    hash;
  273. };
  274.  
  275. /* Data on one input file being compared.  */
  276.  
  277. struct file_data {
  278.     int             desc;    /* File descriptor  */
  279.     char           *name;    /* File name  */
  280.     struct stat     stat;    /* File status from fstat()  */
  281.     int             dir_p;    /* 1 if file is a directory  */
  282.  
  283.     /* Buffer in which text of file is read.  */
  284.     char _huge *    buffer;     /* Allocated size of buffer.  */
  285. #ifdef MSDOS
  286.     /* Allocated size of buffer.  */
  287.     long        bufsize;
  288.     /* Number of valid characters now in the buffer. */
  289.     long        buffered_chars;
  290. #else /* not MSDOS */
  291.     /* Allocated size of buffer.  */
  292.     int            bufsize;
  293.     /* Number of valid characters now in the buffer. */
  294.     int            buffered_chars;
  295. #endif /* not MSDOS */
  296.  
  297.     /* Array of data on analyzed lines of this chunk of this file.  */
  298.     struct line_def *linbuf;
  299.  
  300.     /* Allocated size of linbuf array (# of elements).  */
  301.     int            linbufsize;
  302.  
  303.     /* Number of elements of linbuf containing valid data. */
  304.     int            buffered_lines;
  305.  
  306.     /* Pointer to end of prefix of this file to ignore when hashing. */
  307.     char _huge *prefix_end;
  308.  
  309.     /* Count of lines in the prefix. */
  310.     int prefix_lines;
  311.  
  312.     /* Pointer to start of suffix of this file to ignore when hashing. */
  313.     char _huge *suffix_begin;
  314.  
  315.     /* Count of lines in the suffix. */
  316.     int suffix_lines;
  317.  
  318.     /* Vector, indexed by line number, containing an equivalence code for
  319.        each line.  It is this vector that is actually compared with that
  320.        of another file to generate differences. */
  321.     int           *equivs;
  322.  
  323.     /* Vector, like the previous one except that
  324.        the elements for discarded lines have been squeezed out.  */
  325.     int           *undiscarded;
  326.  
  327.     /* Vector mapping virtual line numbers (not counting discarded lines)
  328.        to real ones (counting those lines).  Both are origin-0.  */
  329.     int           *realindexes;
  330.  
  331.     /* Total number of nondiscarded lines. */
  332.     int            nondiscarded_lines;
  333.  
  334.     /* Vector, indexed by real origin-0 line number,
  335.        containing 1 for a line that is an insertion or a deletion.
  336.        The results of comparison are stored here.  */
  337.     char       *changed_flag;
  338.  
  339.     /* 1 if file ends in a line with no final newline. */
  340.     int            missing_newline;
  341.  
  342.     /* 1 more than the maximum equivalence value used for this or its
  343.        sibling file. */
  344.     int equiv_max;
  345.  
  346.     /* Table translating diff's internal line numbers 
  347.        to actual line numbers in the file.
  348.        This is needed only when some lines have been discarded.
  349.        The allocated size is always linbufsize
  350.        and the number of valid elements is buffered_lines.  */
  351.     int           *ltran;
  352. };
  353.  
  354. /* Describe the two files currently being compared.  */
  355.  
  356. struct file_data files[2];
  357.  
  358. /* Queue up one-line messages to be printed at the end,
  359.    when -l is specified.  Each message is recorded with a `struct msg'.  */
  360.  
  361. struct msg
  362. {
  363.   struct msg *next;
  364.   char *format;
  365.   char *arg1;
  366.   char *arg2;
  367. };
  368.  
  369. /* Head of the chain of queues messages.  */
  370.  
  371. EXTERN struct msg *msg_chain;
  372.  
  373. /* Tail of the chain of queues messages.  */
  374.  
  375. EXTERN struct msg *msg_chain_end;
  376.  
  377. /* Stdio stream to output diffs to.  */
  378.  
  379. EXTERN FILE *outfile;
  380.  
  381. /* Declare various functions.  */
  382.  
  383. #ifdef __STDC__
  384. #define VOID void
  385.  
  386. extern int diff_2_files(struct file_data *, int);
  387. extern void print_context_header (struct file_data *inf, int unidiff_flag);
  388. extern void print_context_script (struct change *script, int unidiff_flag);
  389. extern int diff_dirs (char *name1, char *name2,
  390.               int (*handle_file) (char *, char *, char *, char *, int),
  391.               int depth, int nonex1, int nonex2);
  392. extern void print_rcs_script (struct change *);
  393. extern void print_ed_script (struct change *);
  394. extern void pr_forward_ed_script (struct change *);
  395. extern void print_ifdef_script (struct change *);
  396. extern int read_files (struct file_data *);
  397. extern void print_normal_script (struct change *);
  398. extern int line_cmp (struct line_def *, struct line_def *);
  399. extern  void pfatal_with_name (char *);
  400. extern void *xcalloc (int, int);
  401. extern void print_1_line (char *, struct line_def *);
  402. extern void message (char *,...);
  403. extern void print_message_queue (void);
  404. extern struct change *find_change (struct change *);
  405. extern void error (char *,...);
  406. extern char *concat (char *, char *, char *);
  407. extern int change_letter (int, int);
  408. extern void setup_output (char *, char *, int);
  409. extern void *xmalloc (unsigned int);
  410. extern struct change *find_reverse_change (struct change *);
  411. extern void fatal (char *);
  412. extern void debug_script (struct change *sp);
  413. extern int translate_line_number (struct file_data *, int);
  414. extern void finish_output (void);
  415. extern void perror_with_name (char *);
  416. extern void *xrealloc (void *, unsigned int);
  417. extern void fatal_with_name (char *, char *);
  418. extern void translate_range (struct file_data *, int, int, int *, int *);
  419. extern void print_number_range (char, struct file_data *, int, int);
  420. extern void print_script (struct change *,
  421.               struct change *(*)(struct change *),
  422.               void (*)(struct change *));
  423. extern void analyze_hunk (struct change *, int *, int *, int *, int *, int *, int *);
  424. extern long hread (int fd, void _huge *buffer, long bytes);
  425. extern void _huge *xhalloc (long);
  426. extern void _huge *xhrealloc (void _huge *ptr, long new_size, long old_size);
  427.  
  428. #else
  429. #define VOID char
  430.  
  431. char *xmalloc ();
  432. char *xrealloc ();
  433. char *concat ();
  434. void free ();
  435. char *rindex ();
  436. char *index ();
  437.  
  438. void message ();
  439. void print_message_queue ();
  440.  
  441. #endif /* __STDC__ */
  442. void print_script ();
  443. void translate_range ();
  444.